<?php

namespace app\admin\model\member;

use think\Db;
use think\Model;


class Addrelusr extends Model
{

    
    const PAR_TAG_0 = 0;//所有参与人
    const PAR_TAG_1 = 1;//活动参与人
    const PAR_TAG_2 = 2;//系列参与人


    // 表名
    protected $table = 'address_list';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];



    /*
    * 头部活动标志
    *
    */
    public function getHeadingList()
    {

                $ret = [
                    self::PAR_TAG_0 => [
                        'tag' => self::PAR_TAG_0,
                        'head' => __('所有参与人')
                    ],
                    self::PAR_TAG_1 => [
                        'tag' => self::PAR_TAG_1,
                        'head' => __('活动参与人')
                    ],
                    self::PAR_TAG_2 => [
                        'tag' => self::PAR_TAG_2,
                        'head' => __('系列参与人')
                    ],

                ];


        return $ret;
    }


    public function account()
    {
        return $this->belongsTo('app\admin\model\member\Account', 'account_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    /*
     * 查找是否参与过活动
     * $admin_id 活动举办人
     * $account_id 活动参与人
     */

    public function getIsActById($admin_id,$account_id){
        if(empty($admin_id) || empty($account_id)){
            return false;
        }

        $map['account_id'] = $account_id;
        $map['admin_id'] = $admin_id;

        $res = Db::name('activity_participants')->where($map)->field('id')->find();
        if($res){
            return true;
        }else{
            return false;
        }
    }

    /*
      * 参与人id查找是否有此用户
     * $aid 参与人id
     * $admin_id 活动举办人id
    */
    public static function getAddIdByusrId($aid,$admin_id){
        if(empty($admin_id) || empty($aid)){
            return false;
        }
        $map['type'] = self::PAR_TAG_1;
        $map['account_id'] = $aid;
        $map['admin_id'] = $admin_id;
        $res = Db::name('address_list')->where($map)->field('id')->find();
        unset($map);
        if($res){
            return true;
        }else{
            return false;
        }

    }
}
